package org.sny7.openOfflineList.gui;

import java.awt.GridLayout;

import javax.swing.BorderFactory;
import javax.swing.JComboBox;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.border.TitledBorder;

import org.sny7.openOfflineList.listener.FilterComboBoxModel;
import org.sny7.openOfflineList.util.LanguageChanger;

public class FilterPanel extends JPanel {
	
	private static FilterPanel filterPanel = init();

	private static final long serialVersionUID = 1L;
	
	private FilterPanel() {
		
	}
	
	public static FilterPanel getFilterPanel() {
		LanguageChanger.localeThis(filterPanel, "filterBox-Title");
		return filterPanel;
	}
	
	private static FilterPanel init() {
		FilterPanel filterPanel = new FilterPanel();
		TitledBorder titledBorder = BorderFactory.createTitledBorder("");
		filterPanel.setBorder(titledBorder);
		filterPanel.setLayout(new GridLayout(4, 3, 5, 5));
		
		filterPanel.add(generateLabel("locationLabel-Text"));
		filterPanel.add(generateLabel("sizeLabel-Text"));
		filterPanel.add(generateLabel("languageLabel-Text"));
		
		filterPanel.add(generateComboBox("location"));
		filterPanel.add(generateComboBox("romSize"));
		filterPanel.add(generateComboBox("language"));
		
		filterPanel.add(generateLabel("saveLabel-Text"));
		filterPanel.add(generateLabel("companyLabel-Text"));
		filterPanel.add(generateLabel("sourceLabel-Text"));
		
		filterPanel.add(generateComboBox("save"));
		filterPanel.add(generateComboBox("company"));
		filterPanel.add(generateComboBox("source"));
		
		return filterPanel;
	}
	
	private static JLabel generateLabel(String name) {
		JLabel label = new JLabel();
		LanguageChanger.localeThis(label, name);
		return label;
	}
	
	private static JComboBox generateComboBox(String type) {
		JComboBox combobox = new JComboBox();
		combobox.setModel(new FilterComboBoxModel());
		return combobox;
	}
	
	public void setTitle(String title) {
		TitledBorder border = (TitledBorder) filterPanel.getBorder();
		border.setTitle(title);
		filterPanel.repaint();
	}

}
